<?php
/**
 * @Author: rocky
 * Date: 2019/9/28
 * Time: 11:22
 */


namespace app\shop\controller\api\v1;

use app\common\controller\BaseApiController;
use app\common\facade\Token;
use app\common\model\ShopMemberCard;
use app\common\model\ShopRecharge;
use app\shop\resource\CardsResoure;
use app\shop\resource\MemberResource;

/**
 * 充值套餐
 * Class Goods
 * @package app\shop\controller\api\v1
 */
class Recharge extends BaseApiController
{
    /*
     * 页面数据
     */
    public function getList()
    {
        $data['money'] = Token::getVar('money');
        $data['list'] = ShopRecharge::field('id,money,pay_money')->where('status', 1)->order('pay_money','asc')->select();
        
        $this->successCode($data);
    }
    
    /*
     * 会员套餐数据
     */
    public function getCard()
    {
        $store_id = $this->request->get('store_id');
        $data = ShopMemberCard::with(['member' => function($query) use($store_id){
            $query->where('store_id',$store_id)->where('uid',Token::id());
        }])->where('status',1)->removeOption('order')->order('money','asc')->select();
        $this->successCode(MemberResource::collection($data));
    }
    
    /*
     * 会员套餐详情
     */
    public function getCardInfo()
    {
        $id = $this->request->get('id');
        $store_id = $this->request->get('store_id');
        $data = ShopMemberCard::with(['member'=>function($query) use($store_id){
            $query->where('store_id',$store_id)->where('uid',Token::id())->where('status',1);
        }])->where('id',$id)->where('status', 1)->find();
        $data['user_money'] = Token::getVar('money')?Token::getVar('money'):0;
        $this->successCode(CardsResoure::item($data));
    }
}